/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2023-01-03 11:38:38
 * @LastEditors: 朱安武 549410045@qq.com
 * @LastEditTime: 2023-01-06 16:05:32
 * @FilePath: \elementUi\src\utils\request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from "axios";
import { ElMessage } from 'element-plus'
import {router} from '../router'

const request = axios.create({
    // timeout:10000, 默认时间
    baseURL:'http://121.89.205.189:3000/admin'
})

//请求拦截
request.interceptors.request.use((req)=>{
    req.headers.token = localStorage.getItem('token')
    return req
})

//响应拦截
request.interceptors.response.use((response)=>{
    //登录有误
    if(response.data.code !== '200'){
        //token无效
        if(response.data.code === '10119'){
            router.push('/login')
        }
        //消息提示
            ElMessage(response.data.message)
        
    }
    
    return response
})

export default request;